<template>
	<layout :loading="loading" curPage="user" title="用户列表">
		<block slot="title">
			<authNav href="/pages/user/userEdit" url="/admin/user/info" class="layui-btn layui-btn-sm">
				<i class="layui-icon layui-icon-add-1"></i>
				添加
			</authNav>
		</block>
		
		<conditions :list="conditonList" :conditions="conditions" @submit="submitSearch"></conditions>
		
		<div class="layui-form layui-border-box layui-table-view">

			<tableList :list="page.list" :canSelect="false">

				<block slot="head">
					<th>用户名</th>
					<th>姓名</th>
					<th>手机号码</th>
					<th>角色</th>
					<th>备注</th>
					<th class="autoWidth">最近登录</th>
					<th>状态</th>
					<th>操作</th>
				</block>

				<block slot="body">

					<tr v-for="( x , index) in page.list" :key="index">
						<td class="mainText">{{x.name}}</td>
						<td>{{x.contact}}</td>
						<td>{{x.mobile}}</td>
						<td>{{x.roleNames}}</td>
						<td>{{x.remark}}</td>
						<td>{{x.lastLoginTime}}</td>
						<td>
							<switchBtn :url="'/admin/user/changeStatus?id=' + x.id" @change="switchPage()" name="isUsable" :value="x.isUsable" onText="正常" offText="冻结"></switchBtn>
						</td>
						<td>
							<authNav :href="'/pages/user/userEdit?id=' + x.id" class="layui-btn layui-btn-xs" url="/admin/user/info">
								编辑
							</authNav>
							<authBtn :url="'/admin/user/delete?id='+x.id" confirm="delete" class="layui-btn layui-btn-xs">
								删除
							</authBtn>
						</td>
					</tr>

				</block>

			</tableList>
			
			<paginate :page="page" @switchPage="switchPage" @changePageSize="changePageSize"></paginate>
			
			<emptyTips :loading="loading" :list="page.list"></emptyTips>

			
		</div>


	</layout>
</template>

<script>
	export default {
		data() {
			return {
				conditonList:[
					{title:"用户名",name:"name"}
				],
				baseId:"",
				conditions:{
					name : ""
				},
				loading: true,
				action: "/admin/user/list",
				page: {
					pageNumber: 1,
					lastPage: true,
					totalPage: 1,
					list: [],
					totalRow: 0,
					pageSize: 10
				}
			}
		},

		onShow() {
			var that = this ;
			this.kit.getPage(this.action);
		},

		methods: {
			submitSearch:function(conditions){
				this.conditions = conditions ;
				this.switchPage();
			},
			
			switchPage: function(pageNumber) {
				this.page.pageNumber = pageNumber || this.page.pageNumber ;
				this.kit.getPage(this.action);
			},
			
			changePageSize: function(pageSize) {
				this.page.pageSize = pageSize;
				this.page.pageNumber = 1;
				this.kit.getPage(this.action);
			},
		}
	}
</script>
